﻿using System;
using UnityEngine;

/// <summary>
/// UI接口
/// </summary>
public interface ICreateWindow
{
    void CreateWindow(GameObject go, bool script);
}

/// <summary>
/// UI信息
/// </summary>
public class UIInfo
{
    /// <summary>
    /// 字段  
    /// </summary>
    public string Field { get; set; }
    /// <summary>
    /// 语句段
    /// </summary>
    public string Body { get; set; }
    /// <summary>
    /// 名字
    /// </summary>
    public string Name { get; private set; }
    /// <summary>
    /// 导出字段
    /// </summary>
    public bool IsSelected { get; set; }

    public UIInfo(string name)
    {
        IsSelected = true;
        Name = name;
    }

    public void InitCSInfo(Type type, string path)
    {
        Body = "\n\t\t"; string typeName = type.FullName;
        if (type.Namespace == "UnityEngine") { typeName = type.Name; }
        Field = string.Format("public {0} {1} ", typeName, Name);
        Field = "\n\t" + Field + "{ get; private set; }";

        if (type == typeof(Transform))
        {
            Body += string.Format("{0} = Tf.Find(\"{1}\");", Name, path);
        }
        else if (type == typeof(GameObject))
        {
            Body += string.Format("{0} = Tf.Find(\"{1}\").gameObject;", Name, path);
        }
        else
        {
            Body += string.Format("{0} = Tf.Find(\"{1}\").GetComponent<{2}>();", Name, path, typeName);
        }
    }

    public void InitLuaInfo(Type type, string path)
    {
        Body = "\n\t"; string typeName = "CS." + type.FullName;
        Field = string.Format("\n---@field public {0} {1}", Name, typeName);

        if (type == typeof(Transform))
        {
            Body += string.Format("self.{0} = self:FindTransform('{1}')", Name, path);
        }
        else if (type == typeof(GameObject))
        {
            Body += string.Format("self.{0} = self:FindGameObject('{1}')", Name, path);
        }
        else
        {
            Body += string.Format("self.{0} = self:GetComponent('{1}', {2})", Name, path, typeName);
        }
    }
}